﻿package base
{
    import com.dusk.game.Logger;
    import com.dusk.net.AssetManager;
    import com.dusk.tool.ColorMatrix;
    import com.dusk.tool.HitTest;
    import com.dusk.util.ArrayUtil;
    import com.dusk.util.ClassUtil;
    import com.dusk.util.McUtil;
    import com.dusk.util.RandomUtil;
    import com.dusk.util.RandomUtil;
    import com.dusk.util.ResUtil;
    import com.dusk.util.UtilBase;
    import com.game.data.constant.FrameRate;
    import com.game.data.constant.HitType;
    import com.game.data.vo.GameGadgetVO;
    import com.game.data.vo.HitResultVO;
    import com.game.data.vo.HitVO;
    import com.game.data.vo.PlayerDataVO;
    import com.game.data.vo.attribute.MonsterAttribVO;
    import com.game.data.vo.attribute.RoleAttribVO;
    import com.game.engine.MainGame;
    import com.game.engine.nape.BodyTypeConst;
    import com.game.engine.nape.utils.CBTypes;
    import com.game.engine.nape.utils.CollisionGroup;
    import com.game.engine.phys.RigidBody;
    import com.game.engine.phys.Vector2D;
    import com.game.event.GameEventType;
    import com.game.manager.AnimationManager;
    import com.game.manager.EventManager;
    import com.game.manager.SoundManager;
    import com.game.view.component.GameGadgetType;
    import com.game.view.component.dropItem.DropEquipment;
    import com.game.view.component.dropItem.DropMedicine;
    import com.game.view.display.AnimationClip;
    import com.game.view.display.AnimationLoopType;
    import com.greensock.TweenMax;
    
    import export.aura.AuraBlue;
    import export.aura.AuraPurple;
    import export.aura.AuraRed;
    import export.aura.AuraYellow;
    
    import flash.display.MovieClip;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.geom.Point;
    
    public class BaseMonster extends BaseObject
    {
        
        public function BaseMonster()
        {
            super();
            newHpSlip();//初始化被打血条
            initAttribute();
            curAddEffect = new BaseAddEffect(this);//初始化buff
        }
        
        protected var curAttackTarget:BaseObject;
        protected var hpSlip:Sprite;
        protected var img:MovieClip;
        public var mavo:MonsterAttribVO;
        
        override protected function initBBDC():void
        {
        }
        
        override protected function initCollideArea():void
        {
            super.initCollideArea();
        }
        
        protected function initAttribute():void
        {
            var name:String = ClassUtil.getClassShortName(this);
            mavo = gc.configManager.monsterProxy.getMonsterVoById(name);
            setFullHp();
        }
        
        override public function renderAnimate():void
        {
            super.renderAnimate();
            if (isReadyToDestroy)
            {
                return;
            }
            if (isInvincible())
            {
                alpha = isTransparent ? 0.5 : 1;
            }
            else
            {
                alpha = 1;
            }
            myIntelligence();
            countCD();
            if (mavo.isBoss && beAttackedTimes > 0)
            {
                beAttackedTimes -= 0.07;
                gc.gameInfo.addBeAttTime(mavo.monsterName + "_beatt", beAttackedTimes / 50);
            }
            if (curAttackTarget && curAttackTarget.isDead())
            {
                curAttackTarget = null;
            }
        }
        
        override public function render(ratio:Number = 1):void
        {
            super.render(ratio);
        }
        
        override protected function updatePosition(ratio:Number = 1):void
        {
            if (curAddEffect && curAddEffect.isCannotControlSkill())
            {
                return;
            }
            if (!(isWalkOrRun() || isInSky() || isBeAttacking() || isCanMoveWhenAttack()))
            {
                velocity.x = 0;
            }
            super.updatePosition(ratio);
            if (isFly)
            {
                if (getDefiniteCollideArea().bottom > 700)
                {
                    y -= getDefiniteCollideArea().bottom - 700;
                }
                if (getDefiniteCollideArea().top < -50)
                {
                    y -= getDefiniteCollideArea().top - (-50);
                }
            }
        }
        
        override protected function addBeAttackEffect():void
        {
            if (_framer - timerDict.lastAddBeHitEffect < 4)
            {
                return;
            }
            var effName:String = "MonsterBeHurt" + RandomUtil.randInt(1, 2).toString();
            var eff:AnimationClip = AnimationManager.getAnimationClip(effName);
            eff.loopType = AnimationLoopType.REMOVE_WHEN_END;
            eff.x = getLocalCollideCenter().x;
            eff.y = getLocalCollideCenter().y;
            effectContainer.addChild(eff);
            timerDict.lastAddBeHitEffect = _framer;
//            img = ResUtil.getNewObj("MonsterBeHurt2");
//            img.x = 0;
//            img.y = 0;
//            addChild(img);
        }
        
        /**
         * 掉下去了把他拉回来
         */
        override protected function checkOver():void
        {
            if (y >= 50 * 60)
            {
                y = 50 * 6;
            }
        }
        
        /**
         * 被子弹碰撞
         * @param bul 子弹
         * @param target 子弹主人
         * @return hitResultVO
         */
        override public function beHit(bul:BaseBullet, target:BaseObject):HitResultVO
        {
            var result:HitResultVO = new HitResultVO();
            var vo:HitVO = bul.hitVO;
            result.hitType = vo.hitType;
            if (isDead())
            {
                result.success = false;
                return result;
            }
            if (isInvincible() && !vo.isEnforceHit)
            {
                result.success = false;
                return result;
            }
            if (vo.isCanBeMiss && RandomUtil.randBoolean(getMiss() - target.getHit()))
            {
                result.success = false;
                result.isMiss = true;
                addHurtNumber(result);
                return result;
            }
            if (vo.isBingo)
            {
                result.success = true;
                result.isBingo = true;
                result.hurt = getHpMax() * 2;
                bul.setHurt(getHpMax() * 2);
            }
            MainGame.getIns().battleData.curCombo++;
            curAttackTarget = target;
            var attackBack:Point = getAttackBackSpeed(bul, vo);
            if (!isSteelBody() && !mavo.isStatic)
            {
                setAttackBack(attackBack);
                setStiff(vo.stiffTime);
            }
            if (vo.addEffect.length)
            {
                var copy:Array = UtilBase.clone(vo.addEffect) as Array;
                for each (var item:Object in copy)
                {
                    if (item.time == 0)
                    {
                        item.time = bul.getFrameLeft();
                    }
                }
                addCurAddEffect(copy);
            }
            var isCrit:Boolean = RandomUtil.randBoolean(target.getCrit() - getToughness());
            var critDmg:Number = 1.5 * (100 + target.getCritDamage() - getDeCritDamage()) / 100;
            critDmg = Math.max(critDmg, 1.5);
            var hurt:int = bul.getHurt() * (isCrit ? critDmg : 1);
            hurt = calculateHurt(hurt, bul.hitVO, target);
            reduceHp(hurt);
            beAttackedTimes += vo.addProtection;
            if (mavo.isBoss)
            {
                if (beAttackedTimes > 49)
                {
                    setInvincible(FrameRate.ANIMATE_FRAME_RATE * 6,true);
                    beAttackedTimes = 0;
                }
                gc.gameInfo.addBeAttTime(mavo.monsterName + "_beatt", beAttackedTimes / 50);
            }
            else if (beAttackedTimes > 59)
            {
                setInvincible(FrameRate.ANIMATE_FRAME_RATE * 2,true);
                beAttackedTimes = 0;
            }
            if (isDead())
            {
                setAction("dead");
            }
            showHpSlip();//显示血条
            /*if (gc.flowerSoul.getSoulLevelByType("atk") > 0)
            {
                var data:Object = gc.flowerSoul.getProp_atk();
                if (RandomUtil.randBoolean(data.odds * 100))
                {
                    addCurAddEffect([{
                        "name": BaseAddEffect.TIANTINGZHANSHEN,
                        "time": gc.frameClips * data.duration
                    }]);
                }
            }//花魂破防*/
            EventManager.getIns().dispatchEvent(GameEventType.MONSTER_BE_HIT, [hurt, curAttackTarget]);
            addBeAttackEffect();
            switch (vo.hitType)
            {
                case HitType.PHYSICS:
                case HitType.REAL:
                default:
                    SoundManager.playSound("BePhysicsAttack");
                    break;
                case HitType.MAGIC:
                    SoundManager.playSound("BeMagicAttack");
                    break;
            }
            result.success = true;
            result.hurt = hurt;
            result.isCrit = isCrit;
            result.isMiss = false;
            addHurtNumber(result);
            return result;
        }
        
        override public function reduceHp(value:int = 0):void
        {
            setHp(getHp() - value);
            drawMonsterHp();
            if (isDead())
            {
                if (curAction != "dead")
                {
                    setAction("dead");
                    if (curAttackTarget is BaseHero)
                    {
                        if (BaseHero(curAttackTarget).getPet())
                        {
                            (BaseHero(curAttackTarget).getAttribute() as RoleAttribVO).addExp(mavo.exp * 0.6);
                            BaseHero(curAttackTarget).getPet().getPetData().addExp(mavo.exp * 0.6);
                        }
                        else
                        {
                            (BaseHero(curAttackTarget).getAttribute() as RoleAttribVO).addExp(mavo.exp);
                        }
                        
                    }
                    else if (curAttackTarget is BasePet)
                    {
                        BasePet(curAttackTarget).getPetData().addExp(mavo.exp);
                    }
                }
            }
            if (mavo.isBoss)
            {
                gc.gameInfo.addBossBlood(mavo.monsterName, getHp() / getHpMax());
            }
        }
        
        override public function isDead():Boolean
        {
            return getHp() <= 0;
        }
        
        override public function isWalkOrRun():Boolean
        {
            return curAction == "walk" || curAction == "run";
        }
        
        override public function isNormalHit():Boolean
        {
            return true;
        }
        
        //属性获取接口
        {
            override public function getHpMax():int
            {
                return mavo.hpMax;
            }
            
            override public function getHp():int
            {
                return mavo.hp;
            }
            
            override public function getAtk():int
            {
                return mavo.atk;
            }
            
            override public function getDef():int
            {
                /*if (hasAddEffect(BaseAddEffect.TIANTINGZHANSHEN))
                {
                    return 0;
                }*/
                return mavo.def;
            }
            
            override public function getCrit():int
            {
                return mavo.crit;
            }
            
            override public function getToughness():int
            {
                return mavo.toughness;
            }
            
            override public function getHit():int
            {
                return mavo.hit;
            }
            
            override public function getCritDamage():int
            {
                return mavo.critDamage;
            }
            
            override public function getDeCritDamage():int
            {
                return mavo.deCritDamage;
            }
            
            override public function getMiss():int
            {
                return mavo.miss;
            }
            
            override public function getMagicDef():int
            {
                /*if (hasAddEffect(BaseAddEffect.TIANTINGZHANSHEN))
                {
                    return 0;
                }
                if (hasAddEffect(BaseAddEffect.JIUHUANSHENGJING))
                {
                    return Number(mavo.magicDef) * 0.85;
                }*/
                return mavo.magicDef;
            }
            
            override public function getDeMagicDef():int
            {
                return mavo.deMagicDef;
            }
            
            override public function resetGravity():void
            {
                super.resetGravity();
                if (isFly)
                {
                    gravity = 0;
                    return;
                }
                if (MainGame.getIns().isInSea())
                {
                    gravity = 0.2;
                }
            }
        }
        
        override public function destroy():void
        {
            if (mavo.isBoss)
            {
                var monsterBlood:MovieClip = gc.gameInfo.getChildByName(mavo.monsterName) as MovieClip;
                var id1:int = gc.gameInfo.bossBloodArray.indexOf(monsterBlood);
                var monsterBeHit:MovieClip = gc.gameInfo.getChildByName(mavo.monsterName + "_beatt") as MovieClip;
                var id2:int = gc.gameInfo.beAttArray.indexOf(monsterBeHit);
                if (monsterBlood)
                {
                    for (var ii:int = 0; ii < gc.gameInfo.bossBloodArray.length; ii++)
                    {
                        if (ii > id1)
                        {
                            if (gc.gameInfo.bossBloodArray[ii] != null)
                            {
                                gc.gameInfo.bossBloodArray[ii].y -= 50;
                            }
                            if (gc.gameInfo.beAttArray[ii] != null)
                            {
                                gc.gameInfo.beAttArray[ii].y -= 50;
                            }
                        }
                    }
                    gc.gameInfo.removeChild(monsterBlood);
                    gc.gameInfo.bossBloodArray.splice(id1, 1);
                }
                if (monsterBeHit)
                {
                    gc.gameInfo.removeChild(monsterBeHit);
                    gc.gameInfo.beAttArray.splice(id2, 1);
                }
            }
            if (curAddEffect)
            {
                curAddEffect.destroy();
                curAddEffect = null;
            }
            TweenMax.to(this, 1, {
                "alpha": 0, "onComplete": function (mon:BaseMonster):void
                {
                    removeFromStage(mon);
                }, "onCompleteParams": [this]
            });
            if (mavo.isBoss)
            {
                MainGame.getIns().battleData.levelPassed = true;
            }
            isReadyToDestroy = true;
            for each(var bb:* in magicBulletArray)
            {
                bb.setDisable();
                TweenMax.killChildTweensOf(bb);
                bb.destroy();
            }
            magicBulletArray = [];
            curAttackTarget = null;
            hpSlip = null;
        }
        
        public function setFullHp():void
        {
            setHp(getHpMax());
        }//设置满血为当前生命值和最大血量值的较大值
        
        public function dropAura():void
        {
            var tarRole:BaseObject;
            var tarAura:BaseAura;
            addMedicine();
            fallEquip();
            if (curAttackTarget is BasePet)
            {
                tarRole = (curAttackTarget as BasePet).getSourceRole();
            }
            else if (curAttackTarget is BaseHero)
            {
                tarRole = curAttackTarget;
            }
            if (!tarRole)
            {
                return;
            }
            var num:int = RandomUtil.randInt(2, 5);
            for (num; num > 0; num--)
            {
                tarAura = new AuraPurple(this, tarRole);
                tarAura.x = RandomUtil.randNum(x - 5, x + 5);
                tarAura.y = RandomUtil.randNum(y - 5, y + 5);
                tarAura.setPower(mavo.gxp);
                gc.gameScene.addChild(tarAura);
                gc.pWorld.getAuraArray().push(tarAura);
            }
            num = RandomUtil.randSwitch([0, 1, 2, 3], [18, 3, 1, 1]);
            for (num; num > 0; num--)
            {
                if (RandomUtil.randBoolean(50))
                {
                    if (RandomUtil.randBoolean(50))
                    {
                        tarAura = new AuraRed(this, tarRole);
                        tarAura.setPower(mavo.gxp * 3);
                    }
                    else
                    {
                        tarAura = new AuraBlue(this, tarRole);
                        tarAura.setPower(mavo.gxp * 3);
                    }
                }
                else
                {
                    tarAura = new AuraYellow(this, tarRole);
                }
                tarAura.x = RandomUtil.randNum(x - 20, x + 20);
                tarAura.y = RandomUtil.randNum(y - 20, y + 20);
                gc.gameScene.addChild(tarAura);
                gc.pWorld.getAuraArray().push(tarAura);
            }
        }
        
        override public function addHurtNumber(vo:HitResultVO):void
        {
            super.addHurtNumber(vo);
            if (vo.isBingo || vo.isMiss)
            {
                return;
            }
            var gadgetVO:GameGadgetVO = new GameGadgetVO();
            gadgetVO.value = vo.hurt;
            gadgetVO.position = new Point(x, getCollideArea().top);
            switch (vo.hitType)
            {
                case HitType.PHYSICS:
                    gadgetVO.type = vo.isCrit ? GameGadgetType.NUM_MONSTER_CRIT_HURT_PHYSICS : GameGadgetType.NUM_MONSTER_HURT_PHYSICS;
                    break;
                case HitType.MAGIC:
                    gadgetVO.type = vo.isCrit ? GameGadgetType.NUM_MONSTER_CRIT_HURT_MAGIC : GameGadgetType.NUM_MONSTER_HURT_MAGIC;
                    break;
                case HitType.REAL:
                    gadgetVO.type = vo.isCrit ? GameGadgetType.NUM_MONSTER_CRIT_HURT_REAL : GameGadgetType.NUM_MONSTER_HURT_REAL;
                    break;
            }
            EventManager.getIns().dispatchEvent(GameEventType.ADD_GAME_GADGET, gadgetVO);
        }
        
        public function fallEquip():void
        {
            var monName:String = ClassUtil.getClassShortName(this);
            EventManager.getIns().dispatchEvent(GameEventType.MONSTER_DEAD, monName);
            if (RandomUtil.randInt(mavo.probability))
            {
                try
                {
                    var idx:int = Math.round(Math.random() * (mavo.fallList.length - 1));
                    if (mavo.fallList[idx] || mavo.fallList[idx] != undefined)
                    {
                        var item:DropEquipment = new DropEquipment(mavo.fallList[idx]);
                        var _p:Point = gc.gameScene.localToGlobal(new Point(x, 0));
                        item.x = (_p.x > 930) ? (x - 200) : (_p.x < 10 ? x + 200 : x);
                        item.y = y - 100;
                        gc.gameScene.addChild(item);
                        gc.pWorld.getDropArray().push(item);
                    }
                } catch (e:Event)
                {
                    throw ("生成掉落物" + mavo.fallList[idx] + "失败");
                }
            }
        }
        
        public function addMedicine():void
        {
            var medicine:DropMedicine;
            if (RandomUtil.randBoolean(15))
            {
                medicine = new DropMedicine();
                const medicineType:Array = [DropMedicine.PEACH, DropMedicine.CARROT, DropMedicine.MAGIC_BOTTLE];
                const weightArray:Array = [1, 5, 5];
                medicine.setType(RandomUtil.randSwitch(medicineType, weightArray));
                medicine.x = x;
                medicine.y = y - 75;
                gc.gameScene.addChild(medicine);
                gc.pWorld.getDropArray().push(medicine);
            }
        }
        
        public function faceToTarget():void
        {
            if (curAttackTarget)
            {
                if (x < curAttackTarget.x)
                {
                    turnRight();
                }
                else
                {
                    turnLeft();
                }
            }
        }
        
        override public function getActionHurt(action:String):int
        {
            return super.getActionHurt(action);
        }
        
        override public function cureHp(value:int = 0):void
        {
            if (isDead())
            {
                return;
            }
            if (getHp() + value > getHpMax())
            {
                setHp(getHpMax());
            }
            else
            {
                setHp(getHp() + value);
            }
            if (mavo.isBoss)
            {
                gc.gameInfo.addBossBlood(mavo.monsterName, getHp() / getHpMax());
            }
            super.cureHp(value);
        }
        
        public function setHp(param1:int):void
        {
            mavo.hp = param1;
        }
        
        public function setSHp(param1:int):void
        {
            mavo.hpMax = param1;
        }
        
        protected function countCD():void
        {
            if (isReadyToDestroy)
            {
                return;
            }
            if (mavo.skillCD1[0] > 0)
            {
                mavo.skillCD1[0]--;
            }
            if (mavo.skillCD2[0] > 0)
            {
                mavo.skillCD2[0]--;
            }
            if (mavo.skillCD3[0] > 0)
            {
                mavo.skillCD3[0]--;
            }
            if (mavo.skillCD4[0] > 0)
            {
                mavo.skillCD4[0]--;
            }
        }
        
        protected function beforeSkill1Start():Boolean
        {
            return false;
        }
        
        protected function beforeSkill2Start():Boolean
        {
            return false;
        }
        
        protected function beforeSkill3Start():Boolean
        {
            return false;
        }
        
        protected function beforeSkill4Start():Boolean
        {
            return false;
        }
        
        protected function normalWalk():void
        {
            if (standInObj)
            {
                if (x >= standInObj.x + standInObj.width / 2)
                {
                    turnLeft();
                }
                else if (x <= standInObj.x - standInObj.width / 2)
                {
                    turnRight();
                }
                else if (_framer % FrameRate.ANIMATE_FRAME_RATE == 0)
                {
                    if (RandomUtil.randBoolean(mavo.waitRateWhenNoTarget))
                    {
                        setAction("idle");
                        setStatic();
                        if (isFly)
                        {
                            velocity.y = 0;
                        }
                    }
                    else
                    {
                        randomWalk();
                    }
                }
            }
        }
        
        protected function myIntelligence():void
        {
            if(isAttacking())
            {
                return;
            }
            if (curAddEffect && curAddEffect.isCannotControlSkill())
            {
                return;
            }
            if (!hasTarget())
            {
                normalWalk();
                selectTarget();
            }
            else if (curAttackTarget.isDead())
            {
                curAttackTarget = null;
            }
            else
            {
                hasAttackTarget();
            }
        }
        
        protected function hasAttackTarget():void
        {
            if (isBeAttacking() || isAttacking())
            {
                return;
            }
            //释放技能
            var skillIdx:int = RandomUtil.randInt(1, 4);
            switch (skillIdx)
            {
                case 1:
                    if (int(mavo.skillCD1[1]) != 0)
                    {
                        if (beforeSkill1Start() && mavo.skillCD1[0] == 0)
                        {
                            faceToTarget();
                            releSkill1();
                            mavo.skillCD1[0] = mavo.skillCD1[1];
                            return;
                        }
                        break;
                    }
                    break;
                case 2:
                    if (int(mavo.skillCD2[1]) != 0)
                    {
                        if (beforeSkill2Start() && mavo.skillCD2[0] == 0)
                        {
                            faceToTarget();
                            releSkill2();
                            mavo.skillCD2[0] = mavo.skillCD2[1];
                            return;
                        }
                        break;
                    }
                    break;
                case 3:
                    if (int(mavo.skillCD3[1]) != 0)
                    {
                        if (beforeSkill3Start() && mavo.skillCD3[0] == 0)
                        {
                            faceToTarget();
                            releSkill3();
                            mavo.skillCD3[0] = mavo.skillCD3[1];
                            return;
                        }
                        break;
                    }
                    break;
                case 4:
                    if (int(mavo.skillCD4[1]) != 0)
                    {
                        if (beforeSkill4Start() && mavo.skillCD4[0] == 0)
                        {
                            faceToTarget();
                            releSkill4();
                            mavo.skillCD4[0] = mavo.skillCD4[1];
                            return;
                        }
                    }
            }
            //普攻击
            if (_framer % FrameRate.ANIMATE_FRAME_RATE == 0)
            {
                if (Math.abs(x - curAttackTarget.x) <= mavo.attackRange)
                {
                    if (RandomUtil.randBoolean(mavo.normalAttackRate))
                    {
                        attackTarget();
                    }
                    else
                    {
                        setAction("idle");
                        setStatic();
                        if (isFly)
                        {
                            flyFollowTarget();
                        }
                    }
                }//释放普攻
                else if (!isFly)
                {
                    followTarget();
                }
                else
                {
                    flyFollowTarget();
                }
            }
        }
        
        override public function setAction(action:String):void
        {
            super.setAction(action);
            bbdc.setAction(action);
        }
        
        protected function attackTarget():void
        {
            faceToTarget();
            setAction("attack1");
        }
        
        protected function releSkill1():void
        {
            setAction("skill1");
        }
        
        protected function releSkill2():void
        {
            setAction("skill2");
        }
        
        protected function releSkill3():void
        {
            setAction("skill3");
        }
        
        protected function releSkill4():void
        {
            setAction("skill4");
        }
        
        override protected function onActionOver(action:String):void
        {
            switch (action)
            {
                case "attack1":
                case "skill1":
                case "skill2":
                case "skill3":
                case "skill4":
                    setAction("idle");
                    break;
                case "dead":
                    dropAura();
                    destroy();
            }
        }
        
        protected function followTarget():void
        {
            if (curAttackTarget)
            {
                if (x > curAttackTarget.x)
                {
                    moveLeft();
                }
                else if (x < curAttackTarget.x)
                {
                    moveRight();
                }
            }
        }
        
        protected function flyFollowTarget():void
        {
            if (curAttackTarget)
            {
                if (x > curAttackTarget.x)
                {
                    moveLeft();
                }
                else if (x < curAttackTarget.x)
                {
                    moveRight();
                }
                if (y < curAttackTarget.y - 150)
                {
                    velocity.y = 3;
                }
                else
                {
                    velocity.y = -3;
                }
            }
        }
        
        protected function selectTarget():void
        {
            var tar:BaseObject = McUtil.getNearestObj(this, gc.team.getHeroArray());
            if (AUtils.GetDisBetweenTwoObj(tar, this) <= mavo.alertRange)
            {
                curAttackTarget = tar;
            }
            else
            {
                curAttackTarget = null;
            }
        }
        
        protected function drawMonsterHp():void
        {
            if (isReadyToDestroy || hpSlip == null)
            {
                return;
            }
            hpSlip.graphics.clear();
            hpSlip.alpha = 1;
            var hpPercent:Number = getHp() / getHpMax();
            hpPercent = hpPercent < 0 ? 0 : hpPercent;
            if (getHp() >= 0)
            {
                hpSlip.graphics.lineStyle(1.2, 0);
                hpSlip.graphics.drawRect(0, 5, 50, 5);
                hpSlip.graphics.beginFill(16711680);
                if (getBBDC() == null)
                {
                    hpSlip.graphics.drawRect(0, 5, 50 * hpPercent, 5);
                }
                else
                {
                    if (getBBDC().getDirect() == -1)
                    {
                        hpSlip.graphics.drawRect(0, 5, 50 * hpPercent, 5);
                    }
                    else if (getBBDC().getDirect() == 1)
                    {
                        hpSlip.graphics.drawRect(50 - 50 * hpPercent, 5, 50 * hpPercent, 5);
                    }
                }
                hpSlip.graphics.endFill();
            }
        }
        
        protected function removedHpSlip():void
        {
            if (!isReadyToDestroy && hpSlip != null)
            {
                hpSlip.alpha = 0;
                hpSlip.visible = false;
            }
        }
        
        protected function showHpSlip():void
        {
            if (isReadyToDestroy || hpSlip == null)
            {
                return;
            }
            hpSlip.visible = true;
            hpSlip.alpha = 1;
            if (TweenMax.isTweening(hpSlip))
            {
                TweenMax.killTweensOf(hpSlip, true);
            }
            TweenMax.to(hpSlip, 2, {"alpha": 0, "onComplete": removedHpSlip});
        }
        
        override public function isAttacking():Boolean
        {
            const act:Array = [
                    "attack1",
                    "skill1",
                    "skill2",
                    "skill3",
                    "skill4"
                ];
            return act.indexOf(curAction) != -1;
        }
        
        protected function newHpSlip():void
        {
            hpSlip = new Sprite();
            hpSlip.x = -23;
            hpSlip.y = -collideBox.height - 10;
            hpSlip.visible = false;
            addChild(hpSlip);
        }
        
        private function randomWalk():void
        {
            var _p:Point = gc.gameScene.localToGlobal(new Point(x, 0));
            if (_p.x > 940)
            {
                turnLeft();
            }
            else if (_p.x < 0)
            {
                turnRight();
            }
            else if (Math.random() < 0.5)
            {
                turnLeft();
            }
            else
            {
                turnRight();
            }
        }
        
        protected function hasTarget():Boolean
        {
            return curAttackTarget != null && !curAttackTarget.isDead();
        }
        
        private function removeFromStage(param1:BaseMonster):void
        {
            removeFromParent()
            if (bbdc)
            {
                bbdc.destroy();
                bbdc = null;
            }
        }
        
        override protected function onFirstAdded():void
        {
            var i:int;
            if (mavo.isBoss)
            {
                gc.gameInfo.addBossBlood(mavo.monsterName, getHp() / getHpMax());
                gc.gameInfo.addBeAttTime(mavo.monsterName + "_beatt", 0);
                if (mavo.normalAttackRate == 0)
                {
                    mavo.normalAttackRate = 72.3;
                }
            }//boss参数;
            else
            {
                if (mavo.normalAttackRate == 0)
                {
                    mavo.normalAttackRate = 56.6;
                }
            }//小怪参数;
            
            if (gc.difficulty == 1)
            {
                setSHp(getHpMax() * 1.653);
                setHp(getHp() * 1.653);
                mavo.def *= 1.256;
                mavo.exp *= 1.842;
                mavo.gxp *= 1.842;
                mavo.magicDef += 0.151;
                mavo.probability *= 1.5;
                setHue(-150);
                mavo.normalAttackRate *= 1.1;
                for (i = 1; i <= 4; ++i)
                {
                    mavo["skillCD" + String(i + 1)][0] /= 1.5;
                    mavo["skillCD" + String(i + 1)][1] /= 1.35;
                }
            }//困难模式
            else if (gc.difficulty == 2)
            {
                setSHp(getHpMax() * 0.75);
                setHp(getHp() * 0.75);
                if (getHp() == 0)
                {
                    setHp(1);
                    setFullHp();
                }
                mavo.def *= 0.8;
                mavo.exp *= 1.842;
                mavo.gxp *= 1.842;
                mavo.probability *= 2.988;
                setHue(-100);
                mavo.normalAttackRate *= 3;
                for (i = 1; i <= 4; ++i)
                {
                    mavo["skillCD" + i][0] *= 0.2;
                    mavo["skillCD" + i][1] *= 0.75;
                }
            }//地狱模式
        }//被添加到舞台后执行
    }
}
